import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'

@Component({
  selector: 'cp-image-view',
  templateUrl: './image-view.component.html',
  styleUrls: ['./image-view.component.scss']
})
export class ImageViewComponent implements OnInit {
  @Input() config: any
  @Input() list = []
  @Input() _index = 0
  @Input() _show = false
  @Input()
  get show() {
    return this._show
  }
  set show(value) {
    if (this._show !== value) {
      this._show = value
      this.showChange.emit(value)
    }
  }
  @Input()
  get index() {
    return this._index
  }
  set index(value) {
    if (this._index !== value) {
      this._index = value
      this.indexChange.emit(value)
    }
  }
  @Output() showChange = new EventEmitter()
  @Output() indexChange = new EventEmitter()
  @Output() closeCallBack = new EventEmitter()

  constructor() {}

  ngOnInit() {}

  handleClose(e) {
    e.stopPropagation()
    if (e.target.nodeName !== 'IMG') {
      this.show = false
      //关闭模态框回调
      if (this.closeCallBack) {
        this.closeCallBack.emit()
      }
    }
  }
}
